# -*- coding: utf-8 -*-
import scrapy
from baidutieba.items import BaidutiebaItem


class BaiduSpider(scrapy.Spider):
    name = 'baidu'
    #allowed_domains = ['www.baidu.com']
    start_urls = [r'https://tieba.baidu.com/f?kw=美腿&ie=utf-8&pn=50',
    r'https://tieba.baidu.com/f?kw=美腿&ie=utf-8&pn=100',]

    
    def parse(self,response):
    	
    	urls = response.xpath('//a[@class="j_th_tit "]/@href').extract()
    	for url in urls:
    		link = 'https://tieba.baidu.com'+url
    		yield scrapy.Request(link,callback=self.parse_first)
    def parse_first(self,response):
    	urls = []
    	item = BaidutiebaItem()
    	for file_url in response.xpath('//img[@class="BDE_Image"]/@src').extract():
    		urls.append(file_url)
    	item['image_urls'] = urls
    	return item
    		

